import requests
import base64
import cv2
import json
from datetime import datetime

# image_path = "images/1.png"
# files = {"file": open(image_path, "rb")}
# response = requests.get(url="https://hz-t2.matpool.com:29345")
# print(response.json())
# response = requests.post(url = "https://hz-t2.matpool.com:29345/predict" , files=files)
# print(response.json())

import requests
import json

dataTypeToActions = {
    'base_info': {"msg":"test"},  # 基本信息
    'screen_shot': None,  # 截图并OCR
    'generate_txt': None,  # 转录
    'status': "finished"  # 状态
}
status_data = {
    "ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    "task_id": "658ba113eb998fb01740637e",
    "status": "finished",
    "type": "task_off",
    "data": dataTypeToActions
}
# res = requests.post("http://118.25.20.192:8080/api/status_notify", data=json.dumps(status_data, ensure_ascii=False), headers={"Content-Type": "application/json"})
# res = requests.post("http://118.25.20.192:8080/api/status_notify", json=status_data)

def send_request(task_data):
    url = "https://hz.matpool.com:28900/process_task"
    # url = "http://localhost:8000/process_task"
    headers = {'Content-Type': 'application/json'}

    response = requests.post(url, headers=headers, data=json.dumps(task_data))

    if response.status_code == 200:
        return response.json()
    else:
        raise Exception(f"Request failed with status code {response.status_code}: {response.text}")


# 示例任务数据
task_data = {
    "task_id": "example_task_id",
    "keywords": ["美容"],
    "callback_url": "http://requester-service-url/status-notify"
}

try:
    result = send_request(task_data)
    print(f"Received response: {result}")
except Exception as e:
    print(f"An error occurred: {e}")